'use strict'
let templateConfig = require('../../config/templateConfig')

//物品背包属性
class ItemComponent {
  constructor(){
    let self = this
    let equipment = templateConfig.equipment
    for (let i in equipment) {
      equipment[i].getItemComponent = function() {
        return self.getPropComponent(equipment[i])
      }
    }
    let prop = templateConfig.prop
    for (let i in prop) {
      prop[i].getItemComponent = function(stack, bind) {
        let itemCompent = self.getPropComponent(prop[i])
        if (stack) {
          itemCompent.stack = stack
        }
        if (bind) {
          itemCompent.bind = bind
        }
        return itemCompent
      }
    }
  }

  //生成道具的属性
  getPropComponent(opts) {
    let templateId = Math.floor(opts.templateId)
    if (templateId < 500000) {
      return {
        templateId: templateId, //模板id
        stack: opts.stack || 1, //物品在背包格子叠加数
        bind: opts.bind || 0, //物品是否绑定 0不可交易1可以交易
      }
    } else if (templateId === 600000) { //魂器
      return {
        templateId: templateId,
        name: opts.name || '',
        quality: opts.quality || 1, //品质
        stack: 1, //物品在背包格子叠加数
        lvl: opts.lvl || 1, //装备等级
        mainAttri: opts.mainAttri || {}, //装备主属性
        addAttri: opts.addAttri || {}, //装备附加属性
        solt: opts.solt || [], //宝石槽
        strengthenLvl: opts.strengthenLvl || 0, //强化等级
        skills: opts.skills || [], //技能槽
        bind: opts.bind || 0, //物品是否绑定 0不可交易1可以交易
      }
    } else if (templateId >= 510000 && opts.templateId <= 550000) { //武器
      return {
        templateId: templateId,
        name: opts.name || '',
        quality: opts.quality || 1, //品质
        stack: 1, //物品在背包格子叠加数
        lvl: opts.lvl || 1, //装备等级
        mainAttri: opts.mainAttri || {}, //装备主属性
        addAttri: opts.addAttri || {}, //装备附加属性
        solt: opts.solt || [], //宝石槽
        strengthenLvl: opts.strengthenLvl || 0, //强化等级
        specialAttri: opts.specialAttri || {}, //特殊属性
        bind: opts.bind || 0, //物品是否绑定 0不可交易1可以交易
      }
    } else { //防具
      return {
        templateId: templateId,
        name: opts.name || '',
        quality: opts.quality || 1, //品质
        stack: 1, //物品在背包格子叠加数
        lvl: opts.lvl || 1, //装备等级
        mainAttri: opts.mainAttri || {}, //装备主属性
        addAttri: opts.addAttri || {}, //装备附加属性
        solt: opts.solt || [], //宝石槽
        strengthenLvl: opts.strengthenLvl || 0, //强化等级
        bind: opts.bind || 0, //物品是否绑定 0不可交易1可以交易
      }
    }
  }
}

let itemComponent = new ItemComponent()
module.exports = itemComponent
